# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=akonadi
pkgver=20.04.3
pkgrel=1
pkgdesc="A cross-desktop storage service for PIM data and meta data providing concurrent read, write, and query access"
arch="all !armhf"
url="https://community.kde.org/KDE_PIM"
license="LGPL-2.0-or-later"
depends="mariadb"
depends_dev="qt5-qtbase-dev kcompletion-dev kconfig-dev kconfigwidgets-dev kcoreaddons-dev kdbusaddons-dev ki18n-dev kiconthemes-dev kitemmodels-dev kitemviews-dev kio-dev kwidgetsaddons-dev kwindowsystem-dev kxmlgui-dev kcrash-dev boost-dev shared-mime-info libxml2-dev sqlite-dev"
makedepends="$depends_dev extra-cmake-modules qt5-qttools-dev"
checkdepends="xvfb-run cmd:dbus-run-session"
source="https://download.kde.org/stable/release-service/$pkgver/src/akonadi-$pkgver.tar.xz"
subpackages="$pkgname-dev $pkgname-lang $pkgname-dbg"

build() {
	# akonadi recurses while walking e-mail threads, so give it a decent stack
	LDFLAGS="$LDFLAGS -Wl,-z,stack-size=1024768" \
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_DESIGNERPLUGIN=ON
	cmake --build build
}

check() {
	cd build
	# akonadixml-xmldocumenttest, mimetypecheckertest and akonadi-mysql-testenvironmenttest are broken
	# All sqlite tests are hanging
	# All mysql tests are broken "Cannot connect to non-local host <hostname>"
	# tagmodeltest fails on 32-bit architectures
	local skipped_tests="("
	local tests="
		akonadixml-xmldocument
		mimetypechecker
		akonadi-mysql-testenvironment
		.*sqlite.*
		.*mysql.*
		tagmodel
		"
	case "$CARCH" in
		s390x) tests="$tests
			AkonadiServer-itemcreatehandler
			AkonadiServer-relationhandler
			" ;;
	esac
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)test"
	CTEST_OUTPUT_ON_FAILURE=TRUE dbus-run-session xvfb-run ctest -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}
sha512sums="29612920af6794f096d6ae51d98830f38f4d94bfb3669e11b748fbf7556b2396fac1837f1ee14cfdbc2285164c8b08206d2d46a62d0929354af47c77d9978698  akonadi-20.04.3.tar.xz"
